home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 June: Reference Library / Dev.CD Jun 00 RL Disk 1.toast / mac / Technical Documentation / Develop / develop Issue 25 / develop Issue 25 code / ToolFrontEnd.sea / ToolFrontEnd / ToolFrontEnd Source / ToolFrontEnd Compiler / ToolServer.c / ToolServer.c
Encoding:
C/C++ Source or Header  |  1996-02-15  |  2.4 KB  |  80 lines  |  [TEXT/CWIE]

  1. /* ToolServer.c: How to create and send an AppleEvent to ToolServer. */
  2.  
  3. #include <Errors.h>
  4. #include <Finder.h>
  5. #include <Strings.h>
  6. #include <string.h>
  7.  
  8. #include "ToolServer.h"
  9. #include "SignatureToApp.h"
  10.  
  11.  
  12. /* send an Apple event to ToolServer */
  13.  
  14. OSErr ToolServerCommand(AEDesc *command, CStringHandle *output, CStringHandle *diagnostic,
  15.                             AEIdleUPP idleProc, AEFilterUPP filterProc)
  16. {
  17.     AppleEvent aeEvent, aeReply;
  18.     AEDesc toolServerAddress;
  19.     ProcessSerialNumber toolServerProcess;
  20.     FSSpec appSpec; /* SignatureToApp requires this, documentation to the contrary.... */
  21.     long theLong, theSize;
  22.     DescType theType;
  23.     AEDesc paramDesc;
  24.     OSErr err;
  25.  
  26.     /* default replies */
  27.     *output = NULL;
  28.     *diagnostic = NULL;
  29.     
  30.     /* find the ToolServer */
  31.     err = SignatureToApp(kToolServerCreator, NULL, &toolServerProcess, &appSpec, NULL,
  32.                           Sig2App_LaunchApplication, launchContinue + launchDontSwitch);
  33.     if (err != noErr) return err;
  34.     err = AECreateDesc(typeProcessSerialNumber, (Ptr) &toolServerProcess, sizeof(ProcessSerialNumber),
  35.                          &toolServerAddress);
  36.     if (err != noErr) return err;
  37.  
  38.     /* Create the ToolServer Apple Event */
  39.     err = AECreateAppleEvent('misc', 'dosc', &toolServerAddress, kAutoGenerateReturnID,kAnyTransactionID, 
  40.                                &aeEvent);
  41.     AEDisposeDesc(&toolServerAddress);
  42.     if (err != noErr) return err;
  43.  
  44.     /* add the command descriptor to the event */
  45.     err = AEPutParamDesc(&aeEvent, keyDirectObject, command);
  46.     if (err != noErr) { AEDisposeDesc(&aeEvent); return err; }
  47.     
  48.     /* send the apple event */
  49.     err = AESend(&aeEvent, &aeReply, kAEWaitReply + kAENeverInteract, kAENormalPriority,
  50.                  kNoTimeOut, idleProc, filterProc);
  51.     AEDisposeDesc(&aeEvent);
  52.     if (err != noErr) return err;
  53.  
  54.     /* check for an error return */
  55.     err = AEGetParamPtr(&aeReply, keyErrorNumber, typeInteger, &theType, &theLong,
  56.                         sizeof(long), &theSize);
  57.     if (err != noErr || (err = theLong) != noErr)
  58.         return err;
  59.  
  60.     /* get the command output */
  61.     err = AEGetParamDesc (&aeReply, keyDirectObject, typeChar, ¶mDesc);
  62.     if (err == noErr)
  63.         *output = (CStringHandle)paramDesc.dataHandle;
  64.     
  65.     /* get the diagnostic output */
  66.     err = AEGetParamDesc (&aeReply, 'diag', typeChar, ¶mDesc);
  67.     if (err == noErr)
  68.         *diagnostic = (CStringHandle)paramDesc.dataHandle;
  69.     
  70.     /* get the MPW status -- it becomes our error return */
  71.     err = AEGetParamPtr(&aeReply, 'stat', typeInteger, &theType, &theLong,
  72.                         sizeof(long), &theSize);
  73.     if (err == noErr)
  74.         err = theLong;
  75.  
  76.     AEDisposeDesc(&aeReply);
  77.  
  78.     return err;
  79. }
  80.